<?php

Raise::load('core.RaiseObject');
Raise::load('core.RaiseConvert');

/**
 * RaiseOAuthSignatureMethod class
 * Define a OAuth signature method
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @abstract
 * @package phpraise.library.oauth.core
 * @since 1.2
 */
abstract class RaiseOAuthSignatureMethod extends RaiseObject {
    
    /**
     * The request parameters that was used
     * @var RaiseOAuthHeader
     */
    private $header;
    
    /**
     * The OAuth consumer
     * @var RaiseOAuthConsumer
     */
    private $consumer;
    
    /**
     * The response the OAuth service provider is giving back
     * @var RaiseOAuthResponse
     */
    private $response;
    
    public function __construct($request, $consumer, $response = null){
        $this->request = $request;
        $this->consumer = $consumer;
        $this->response = $response;
    }
    
    /**
     * Get the name of this signature method
     * @return string
     */
    abstract public function name();
    
    /**
     * Build the signature based on the parameters
     * @return string
     */
    abstract public function build();
    
    /**
     * Check if a signature is valid based on the parameters provided.
     * @param string|RaiseString $signature
     * @return boolean 
     */
    public function check($signature){
        if(!is_string($signature)){
            $signature = RaiseConvert::toString($signature);
        }
        return $this->build() == $signature;
    }
    
    /**
     * Get the request sent from the OAuth Consumer
     * @return RaiseOAuthRequest
     */
    public function request(){
        return $this->request;
    }

    /**
     * Get the OAuth Consumer involved with the request
     * @return RaiseOAuthConsumer
     */
    public function consumer(){
        return $this->consumer;
    }

    /**
     * Get the response the OAuth Service Provider is providing
     * @return RaiseOAuthResponse
     */
    public function response(){
        return $this->response;
    }
    
}
